package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.OrderInfoBO;
import com.ruoyi.system.domain.PropertyFeedback;
import com.ruoyi.system.domain.Story;
import com.ruoyi.system.mapper.PropertyMapper;
import com.ruoyi.system.mapper.StoryMapper;
import com.ruoyi.system.service.PropertyService;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class PropertyServiceImpl implements PropertyService {

    @Autowired
    private StoryMapper storyMapper;
    @Autowired
    private PropertyMapper propertyMapper;

    @Override
    public List<OrderInfoBO> selectPropertyList(String studentId, String classID, String departmentID, String beginTime, String endTime) throws Exception {

        String flag = studentId + classID + departmentID;
        List<Story> list = null;
        if (StringUtils.isEmpty(flag)){


            if (StringUtils.isNotEmpty(beginTime)){  //当开始时间不为空时，才需要用时间去过滤
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
                if (StringUtils.isEmpty(endTime)) //如果没有传入结束时间就默认是今天
                {
                    Date now = new Date();
                    endTime = format.format(now);
                }
                list = storyMapper.selectStoryListByTime(beginTime, endTime);

            }else {
                list = storyMapper.selectStoryList();
            }

        }else if (StringUtils.isNotEmpty(studentId)){
            list = storyMapper.selectStoryListByStudentId(studentId);
        }else if (StringUtils.isNotEmpty(classID)){
            list = storyMapper.selectStoryListByClassID(classID);
        }else{
            list = storyMapper.selectStoryListByDepartmentID(departmentID);
        }


        return null;
    }

    @Override
    public List<OrderInfoBO> getThreeDaysOrders(String studentId, String classID, String departmentID, String beginTime, String endTime) throws Exception {

        return null;
    }

    @Override
    public List<OrderInfoBO> getOrderInfoByCreateTime(String createTime,int days,int status){
        List<OrderInfoBO> list = null;

        if(days == 3) {
            list = propertyMapper.getOrderInfoByCreateTime(createTime);
        }else if(days == 5){
            list = propertyMapper.getOrderInfoByDays(createTime,status);
        }else if(days == 7){
            list = propertyMapper.getOrderInfoByDays(createTime,status);
        }else {
            list = propertyMapper.getOrderInfoByDays(createTime,status);
        }
        return list;
    }

    @Override
    public OrderInfoBO getOrderInfoById(int id) {
       return propertyMapper.getOrderInfoById(id);
    }

    @Override
    public List<OrderInfoBO> selectOrderInfoListByTime(String beginTime) {
        return propertyMapper.selectOrderInfoListByTime(beginTime);
    }

    @Override
    public PropertyFeedback getFeedbackById(int id) {
        return propertyMapper.getFeedbackById(id);
    }

    @Override
    public boolean insertFeedback(PropertyFeedback propertyFeedback) {
        propertyMapper.insertFeedback(propertyFeedback);
        return true;
    }

    @Override
    public boolean updateFeedback(PropertyFeedback propertyFeedback) {
        propertyMapper.updateFeedback(propertyFeedback);
        return true;
    }

    @Override
    public List<OrderInfoBO> getFeedback() {
        return propertyMapper.getFeedback();
    }
}
